package com.cskaoyan.controller;

import com.cskaoyan.bean.Ad;
import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.QueryParams;
import com.cskaoyan.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/ad")
public class AdController {

    @Autowired
    AdService adService;

    @RequestMapping("list")
    public BaseRespVo list(QueryParams params){
        BaseData baseData = adService.AdvertList(params);
        return BaseRespVo.ok(baseData);
    }

    @RequestMapping("create")
    public BaseRespVo createAd(@RequestBody Ad ad) {
        Ad data = adService.createAd(ad);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo updateAd(@RequestBody Ad ad) {
        Ad data = adService.updateAd(ad);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    public BaseRespVo deletedAd(@RequestBody Ad ad) {
        adService.deleteAd(ad);
        return BaseRespVo.ok();
    }
}
